<template>
  <Dialog v-model="dialogVisible" title="详情" width="800">
    <el-descriptions :column="1" :label-width="130" border>
      <el-descriptions-item label="日志编号">
        {{ detailData.id }}
      </el-descriptions-item>
      <el-descriptions-item label="登录类型">
        <dict-tag :options="system_user_login_type" :value="detailData.loginType" />
      </el-descriptions-item>
      <el-descriptions-item label="登录账号">
        {{ detailData.loginName }}
        <dict-tag
          v-if="detailData.userType"
          :options="common_user_type"
          :value="detailData.userType"
        />
        <span v-if="detailData.userId">（{{ detailData.userId }}）</span>
      </el-descriptions-item>
      <el-descriptions-item label="登录IP/地点">
        {{ detailData.ip }}
        <template v-if="detailData.location"> / {{ detailData.location }}</template>
      </el-descriptions-item>
      <el-descriptions-item label="浏览器/系统">
        {{ detailData.browser }} / {{ detailData.os }}
      </el-descriptions-item>
      <el-descriptions-item label="浏览器UA">
        {{ detailData.userAgent }}
      </el-descriptions-item>
      <el-descriptions-item
        label="扩展信息"
        v-if="detailData.extension && detailData.extension != '{}'"
      >
        {{ detailData.extension }}
      </el-descriptions-item>
      <el-descriptions-item label="登录状态">
        <el-tag
          :type="detailData.success == BoolFlagEnum.Yes ? 'success' : 'danger'"
          disable-transitions
        >
          {{ detailData.statusCode }}
        </el-tag>
        / {{ detailData.msg }}
      </el-descriptions-item>
      <el-descriptions-item label="登录时间">
        {{ detailData.loginTime }}
      </el-descriptions-item>
      <el-descriptions-item label="登录耗时"> {{ detailData.timeCost }}ms </el-descriptions-item>
      <el-descriptions-item label="TraceId">
        {{ detailData.traceId }}
      </el-descriptions-item>
    </el-descriptions>
  </Dialog>
</template>

<script setup lang="ts">
import { LoginLogVO } from '@/api/system/login_log'
import { BoolFlagEnum } from '@/utils/constants'

defineOptions({ name: 'SystemLoginLogDetail' })

const { common_user_type } = useDict(DICT_TYPE.common_user_type)
const { system_user_login_type } = useIntDict(DICT_TYPE.system_user_login_type)

const dialogVisible = ref(false) // 弹窗的是否展示
const detailData = ref<LoginLogVO>({} as LoginLogVO) // 详情数据

/** 打开弹窗 */
const open = async (data: LoginLogVO) => {
  dialogVisible.value = true
  detailData.value = data
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>

<style scoped lang="scss"></style>
